package com.odp.mapper;

import com.odp.entity.PerferGroup;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PerferGroupMapper {
    //根据用户id获取  社区偏好s    (社区偏好的type为0)
    @Select("select * from t_perfergroup where user_id=#{userId} and type=0")
    public PerferGroup getPerferGroupByUser(int userId);

    //确定perfergroup表中用户是否已经有了这个偏好
    @Select("select * from t_perfergroup where user_id=#{userId} and perfer_id=#{perferId} and type=0 ")
    public PerferGroup checkPerfer(@Param("userId") int userId, @Param("perferId") int perferId);

    //偏好权重+1
    @Update("update t_perfergroup set weights=weights+1 where user_id=#{userId} and perfer_id=#{perferId}")
    public int addWeights(@Param("userId") int userId, @Param("perferId") int perferId);

    //偏好权重 -2
    @Update("update t_perfergroup set weights=weights-2 where user_id=#{userId} and perfer_id=#{perferId}")
    public int decreaseWeights(@Param("userId") int userId, @Param("perferId") int perferId);

    //新添偏好 社区偏好  初始权重为10
    @Insert("insert into t_perfergroup(user_id,perfer_id,weights,type) values (#{userId},#{perferId},10,0)")
    public int addPerfer(@Param("userId") int userId, @Param("perferId") int perferId);

    //新添偏好 社区偏好  初始权重为0
    @Insert("insert into t_perfergroup(user_id,perfer_id,weights,type) values (#{userId},#{perferId},0,0)")
    public int addPerferUnlike(@Param("userId") int userId, @Param("perferId") int perferId);

    //获取用户所有weights大于0的偏好
    @Select("select perfer_id from t_perfergroup where user_id=#{userId} and weights>0")
    public List<Integer> selectPerfersOverZero(int userId);
}
